package swind.common.ExamTest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import swind.web.vo.TestVo;

public class TestUtils {
	private static final int MULTI_TEST_COUNT = 5;
	private static final int MULTI_TEST_TYPE = 2;
	private static final int SINGLE_TEST_TYPE = 1;
	
	public static boolean checkSubjectScoreAndCount(int totalTestCount,int totalTestScore,Map<Integer,Integer> testTypeScoreMap){
		
		//最小题数
		if(MULTI_TEST_COUNT>totalTestCount){
			return false;
		}
		
		//最小分数
		Integer mulitTestScore = testTypeScoreMap.get(MULTI_TEST_TYPE);
		if(mulitTestScore==null){
			return false;
		}
		if(totalTestScore<mulitTestScore * MULTI_TEST_COUNT){
			return false;
		}
		
		Integer singleTestScore = testTypeScoreMap.get(SINGLE_TEST_TYPE);
		if(singleTestScore==null){
			return false;
		}
		
		//计算单选题数目
		Integer singleTestCount = totalTestCount - MULTI_TEST_COUNT;
		Integer singleTestSubjectTotalScore = totalTestScore - (mulitTestScore * MULTI_TEST_COUNT);
		Integer SingleTestOwnTotalScore = singleTestCount * singleTestScore;
		if(!(singleTestSubjectTotalScore.compareTo(SingleTestOwnTotalScore)==0)){
			return false;
		}
		
		return true;
	}
	
	public static Map<Integer,Integer> getTestConutByScore(int totalTestCount,Map<Integer,Integer> testTypeScoreMap){
		Map<Integer,Integer> testConutMap = new HashMap<Integer,Integer>();
		for(Integer key:testTypeScoreMap.keySet()){
			if(key.compareTo(new Integer(MULTI_TEST_TYPE))==0){
				testConutMap.put(key, MULTI_TEST_COUNT);
			}else if(key.compareTo(new Integer(SINGLE_TEST_TYPE))==0){
				testConutMap.put(key, totalTestCount-MULTI_TEST_COUNT);
			}
		}
		
		return testConutMap;
	}

	public static List<Integer> getRandomList(int oneTotalCount, List<TestVo> oneTotalTest) {
		List<Integer> resultTestIdList =new ArrayList<Integer>();
		int listCount = oneTotalTest.size();
		if(oneTotalCount>oneTotalTest.size()){
			return null;
		}
		for(int i=0;i<oneTotalCount;i++){
			int randomNum = (int) (listCount*Math.random());
			resultTestIdList.add(oneTotalTest.get(randomNum).getId());
			
			oneTotalTest.remove(randomNum);
			listCount = oneTotalTest.size();
		}
		
		return resultTestIdList;
	}
	
	
	
}
